function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function e(t, e) {
    return e.forEach(function(e) {
        var a = t.find(function(t) {
            return +t.catid == +e;
        });
        a && (a.isSelected = !0);
    }), t;
}

function a(t) {
    return t.filter(function(t) {
        return 2 === t.level;
    });
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var i = t(require("./api2")), r = t(require("./util")), s = {
    addTo: function(t) {
        t.setData({
            cateList: [],
            selectedCateArr: []
        }), Object.assign(t, {
            loadCategoryList: function(t) {
                var r = this, s = this.data.site.navid, c = this.data.selectedCateArr;
                wx.showLoading({
                    title: "加载数据中...",
                    mask: !0
                }), i.default.site.category.listsv2({
                    data: {
                        navid: s,
                        op: "set"
                    },
                    desc: "加载分类数据",
                    complete: wx.hideLoading
                }).then(function(i) {
                    "service" === t && (i = a(i));
                    var s = e(i, c);
                    r.setData({
                        cateList: s
                    });
                });
            },
            createCategory: function(t) {
                var e = this, a = this.data.site, s = a.sid, c = a.navid;
                i.default.site.category.add({
                    data: {
                        sid: s,
                        navid: c,
                        catname: t
                    },
                    desc: "分类创建"
                }).then(function(t) {
                    wx.showToast({
                        title: "分类创建成功"
                    });
                    var a = r.default.extend(t, {
                        isSelected: !0
                    }), i = e.data, s = i.cateList, c = i.selectedCateArr;
                    s.push(a), c.push("" + a.catid), e.setData({
                        cateList: s,
                        selectedCateArr: c
                    });
                });
            },
            toggleSelectCategory: function(t) {
                var e = t.currentTarget.dataset.index, a = this.data, i = a.cateList, r = a.selectedCateArr, s = a.mode, c = i[e], n = c.catid, d = c.isSelected;
                if ("view" === s) {
                    if (c.isSelected = !d, d) {
                        var o = r.indexOf("" + n);
                        r.splice(o, 1);
                    } else r.push(n);
                    this.setData({
                        cateList: i,
                        selectedCateArr: r
                    });
                }
            },
            formatSelectedCategoryArr: function(t) {
                var e = this.data.cateList;
                return t.map(function(t) {
                    var a = e.find(function(e) {
                        return +e.catid == +t;
                    });
                    return {
                        catid: t,
                        catname: a.catname
                    };
                });
            },
            saveCategorySelectedInfo: function() {
                var t = this.data.selectedCateArr, e = this.formatSelectedCategoryArr(t);
                this.$emit("select.category", e), wx.navigateBack();
            }
        });
    }
};

exports.default = s;